const express =require('express')

const app = express()

app.use(express.urlencoded())//使用中间件才可以使用requset.body
app.use(express.json())
app.post('/adduser',(request,response)=>{
    console.log('query',request.query)
    const {
        name,
        age,
        sex
    }=request.body
    if(!name||!age||!sex){
        return response.send({
            code:10001,
            msg:'添加失败',
            data:'null'

        })
    }
    response.send({
        code:10000,
        msg:'添加成功',
        data:'null'
    })

})
//防止跨域
app.get('/5',(request,response)=>{
    response.sendFile(__dirname+'/post请求.html')
})
app.listen(8885,()=>{
    console.log('启动成功，请访问http://127.0.0.1:8885')
})